add_library(simdutf-include-source INTERFACE)
target_include_directories(simdutf-include-source INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
add_library(simdutf-source INTERFACE)
target_sources(simdutf-source INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/simdutf.cpp)
target_link_libraries(simdutf-source INTERFACE simdutf-include-source)
add_library(simdutf simdutf.cpp)
target_include_directories(simdutf PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> )
target_include_directories(simdutf PUBLIC "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>")

if(MSVC)
  if("${MSVC_TOOLSET_VERSION}" STREQUAL "140")
    target_compile_options(simdutf PRIVATE /W0 /sdl)
    set(SIMDUTF_LEGACY_VISUAL_STUDIO TRUE)
  else()
    target_compile_options(simdutf PRIVATE /WX /W3 /sdl /w34714) # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4714?view=vs-2019
  endif()
else(MSVC)
  if(NOT WIN32)
    target_compile_options(simdutf INTERFACE -fPIC)
  endif()
  target_compile_options(simdutf PRIVATE -Wall -Wextra -Weffc++)
  target_compile_options(simdutf PRIVATE -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion -Wunused-function)
  #target_compile_options(simdutf PRIVATE -Wfatal-errors)
endif(MSVC)

# workaround for GNU GCC poor AVX load/store code generation
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86(_64)?)$"))
  target_compile_options(simdutf PRIVATE -mno-avx256-split-unaligned-load -mno-avx256-split-unaligned-store)
endif()

if(SIMDUTF_ALWAYS_INCLUDE_FALLBACK)
  message(STATUS "SIMDUTF_ALWAYS_INCLUDE_FALLBACK is set to ${SIMDUTF_ALWAYS_INCLUDE_FALLBACK}")
  target_compile_definitions(simdutf PRIVATE SIMDUTF_IMPLEMENTATION_FALLBACK=1)
endif()

if(SIMDUTF_SANITIZE)
  target_compile_options(simdutf PUBLIC -fsanitize=address  -fno-omit-frame-pointer -fno-sanitize-recover=all)
  target_compile_definitions(simdutf PUBLIC ASAN_OPTIONS=detect_leaks=1)
  target_link_libraries(simdutf PUBLIC -fsanitize=address  -fno-omit-frame-pointer -fno-sanitize-recover=all)
endif()
if(SIMDUTF_SANITIZE_UNDEFINED)
  target_compile_options(simdutf PUBLIC -fsanitize=undefined -fno-sanitize-recover=all)
  target_link_libraries(simdutf PUBLIC -fsanitize=undefined)
endif()
if(SIMDUTF_SANITIZE_THREAD)
    target_compile_options(simdutf PUBLIC -fsanitize=thread)
    target_link_libraries(simdutf PUBLIC -fsanitize=thread)
endif()
if(MSVC AND BUILD_SHARED_LIBS)
  set(SIMDUTF_WINDOWS_DLL TRUE)
endif()
